package modules
{
	import frameworks.modules.BaseModule;
	import frameworks.widgets.Result;
	
	import models.Model;
	import models.user.CurUserVO;
	import models.user.UserVO;
	
	import modules.views.UserInfo;

	public class UserInfoCon extends BaseModule
	{
		private var _facade:Facade = Facade.SingleInstance();
		private var _model:Model = _facade.model;
		private var _userInfo:UserInfo;
		private var _curUserVO:CurUserVO;
		
		public function UserInfoCon(id:String, view:UserInfo, options:Object=null)
		{
			_userInfo = view;
			super(id, view, options);
		}
		override public function buildEnvironmentCompleted(result:Result):void{
			if(result.valid){
				_curUserVO = _model.curUser;
				_curUserVO.addWatcher(this,"user",watch_curUser_user);
			}else{
				_userInfo.con.dataProvider = ['获取用户信息失败，重试'];
			}
		}
		private function watch_curUser_user(init:Boolean):void{
			_userInfo.uname.text = _curUserVO.user.uname;
			_userInfo.con.dataProvider = ['登录',"注册"];
		}
	}
}